import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @USER: Administrator
 * @DATE: 2024/9/18 下午7:25
 * @VERSION: 1.0.0
 */
public class LC500 {

    private static final String[] LETTER_LINE = new String[]{"qwertyuiop","asdfghjkl","zxcvbnm"};

    public static void main(String[] args) {
        LC500 lc500 = new LC500();
        System.out.println(Arrays.toString(lc500.findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"})));
    }

    public String[] findWords(String[] words) {
        List<String> result = new ArrayList<>();
        for (String word : words) {
            String temp = word.toLowerCase();
            int i = 0;
            for (;i<LETTER_LINE.length;i++) {
                if (LETTER_LINE[i].contains(temp.charAt(0)+"")) {
                    break;
                }
            }
            boolean flag = true;
            for (int j = 0; j < temp.length(); j++) {
                if (LETTER_LINE[i].indexOf(temp.charAt(j)) == -1) {
                    flag = false;
                    break;
                }
            }

            if (flag) {
                result.add(word);
            }
        }

        String[] res = new String[result.size()];
        for (int i = 0; i < result.size(); i++) {
            res[i] = result.get(i);
        }
        return res;
    }

}
